﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors;
using DevTeam;

using System;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class StokOzet : XForm
    {
        public StokOzet()
        {
            InitializeComponent();
        }

        private void StokOzet_Load(object sender, EventArgs e)
        {
            gridControl1.Visible = false;
            gridView1.Init("GetStoklarEsti", 0);

            // Set the help text description for the FolderBrowserDialog.
            this.folderBrowserDialog1.Description = "Select the directory that you want to use.";

            // Do not allow the user to create new files via the FolderBrowserDialog.
            //this.folderBrowserDialog1.ShowNewFolderButton = false;

            // Default to the My Documents folder.
            //this.folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;


            //TODO: CEDocs meselesi... FileManager.CreateTempFolder("CEDocs", true);


            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                string folderName = folderBrowserDialog1.SelectedPath;

                DataTable dtCust = Session.DataManager.ExecuteDataTable("GetCustomersEsti");
                foreach (DataRow dr in dtCust.Rows)
                {
                    //Notify(dr["Name"].ToString());
                    gridView1.RefreshDataSource(true, "GetStoklarEsti", intParse(dr["CustomerId"]));
                    gridView1.FormatAsNumber(1, "Qty", "QtyAyrilan", "QtyInTransit");
                    gridView1.AddSummary("Qty", "QtyAyrilan", "QtyInTransit");

                    string fileName = folderName + "\\" + dr["Name"].ToString() + ".xlsx";
                    gridView1.Export(fileName);                 

                }

                XtraMessageBox.Show("Done.");
            }

        }

    }
}
